home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / misc / show1.0.lha / show / RCS / showprefs.c,v < prev    next >
Encoding:
Text File  |  1994-12-07  |  19.1 KB  |  728 lines

  1. head    1.70;
  2. access;
  3. symbols
  4.     fontscreen:1.70
  5.     good:1.60;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.70
  11. date    94.12.04.23.23.30;    author jsshephe;    state Exp;
  12. branches;
  13. next    ;
  14.  
  15.  
  16. desc
  17. @original
  18. @
  19.  
  20.  
  21. 1.70
  22. log
  23. @Made the program reopen its interface on screenmode and font changes.
  24. @
  25. text
  26. @/*
  27.  * GUI Designed by : -- Jeff Shepherd
  28.  * #define TEST to use an internal test list
  29.  *
  30.  * $Id: showprefs.c,v 1.60 1994/12/04 02:37:31 jsshephe Exp jsshephe $
  31.  * $Revision: 1.60 $
  32.  * $Log: showprefs.c,v $
  33.  * Revision 1.60  1994/12/04  02:37:31    jsshephe
  34.  * Made the GUI font sensitive.
  35.  * Made a few optimizations.
  36.  *
  37.  * Revision 1.57  1994/11/27  22:44:00    jsshephe
  38.  * Changed GfxBase.
  39.  * Added COPY gadget under listview.
  40.  *
  41.  * Revision 1.56  1994/08/19  01:35:17    jsshephe
  42.  * fixed a stupid syntax error from v1.55
  43.  *
  44.  * Revision 1.55  1994/08/19  01:30:20    jsshephe
  45.  * added version string
  46.  *
  47.  * Revision 1.54  1994/08/18  21:31:26    jsshephe
  48.  * Made the preferences file use variable length strings instead of fixed length
  49.  *
  50.  * Revision 1.53  1994/08/18  18:41:05    jsshephe
  51.  * Moved MakeNode() and DestroyList() to loadsave.c
  52.  *
  53.  * Revision 1.52  1994/08/18  06:28:39    jsshephe
  54.  * Rearranged some things
  55.  * Made the Test array conditionally compiled
  56.  * At ALPHA test stage now
  57.  *
  58.  * Revision 1.51  1994/08/17  21:33:46    jsshephe
  59.  * added zoom gadget
  60.  * made a test list for the listview
  61.  * had the string gadgets fill in when the appropriate list item was pressed
  62.  *
  63.  * Revision 1.5  1994/08/17  18:03:12  jsshephe
  64.  * Added font sensitivity and layout recalculation based on font size
  65.  *
  66.  * Revision 1.2  1994/08/12  22:52:16  jsshephe
  67.  * added main()
  68.  *
  69.  * Revision 1.1  1994/08/12  21:53:57  jsshephe
  70.  * Initial revision
  71.  * Constructed from GadtoolsBox
  72.  */
  73.  
  74. #define INTUI_V36_NAMES_ONLY
  75. /* #define TEST */
  76.  
  77. #include <dos/dos.h>
  78. #include <dos/notify.h>
  79. #include <exec/types.h>
  80. #include <exec/memory.h>
  81. #include <intuition/intuition.h>
  82. #include <intuition/gadgetclass.h>
  83. #include <libraries/gadtools.h>
  84. #include <graphics/gfxbase.h>
  85.  
  86. #include <proto/dos.h>
  87. #include <proto/exec.h>
  88. #include <proto/intuition.h>
  89. #include <proto/gadtools.h>
  90.  
  91. #include <clib/alib_protos.h>
  92. #include <string.h>
  93. #include <stdio.h>
  94. #include <stdlib.h>
  95. #include "showprefs.h"
  96.  
  97. /* version string */
  98. char version[] = "\0$VER: Show Preferences program version 1.0";
  99. BOOL FromWB;
  100.  
  101. #ifdef TEST
  102. /* for testing purposes only */
  103. /* constructs a dummy node list so I can save an initial prefs file */
  104. struct SuffixNode test[] = {
  105.     "iff",  "dsound -2 -f", TRUE,
  106.     "ps",   "gs", TRUE,
  107.     "jpg",  "utilities:viewtek/vt", TRUE,
  108.     "gif",  "utilities:viewtek/vt", TRUE
  109. };
  110. #endif
  111.  
  112.  
  113. /* protos */
  114. void panic(char *error, int retval);
  115. void ComputeGadgets(UWORD, UWORD);
  116. void CreateWindow();
  117. void DestroyWindow();
  118. #ifdef TEST
  119. struct List *MakeList(struct SuffixNode *, int);
  120. #endif
  121.  
  122. struct IntuitionBase *IntuitionBase;
  123. struct Library *GadToolsBase, *AslBase, *IFFParseBase;
  124. struct GfxBase *GfxBase;
  125.  
  126. struct Screen     *Scr = NULL;
  127. APTR          VisualInfo = NULL;
  128. struct Window     *PrefsWnd = NULL;
  129. struct Gadget     *PrefsGList = NULL;
  130. struct Menu     *PrefsMenus = NULL;
  131. struct Gadget  *PrefsGadgets[Prefs_CNT];
  132. UWORD        PrefsLeft = 0;
  133. UWORD        PrefsTop = 0;
  134. UWORD        PrefsWidth = 400;
  135. UWORD        PrefsHeight = 150;
  136. UBYTE        *PrefsWdt = "Show Prefs";
  137. struct TextAttr  Font;
  138. UWORD         FontX, FontY;
  139. UWORD         OffX, OffY;
  140.  
  141. struct List *Suffix_List, *Duplicate;
  142.  
  143.  
  144. /* dimensions for Zoom- to be filled in later */
  145. UWORD Zoom[4] = {0,0,0,0};
  146.  
  147. #define Prefs_TNUM 2
  148.  
  149. /* Menus - has lookup table in userdata */
  150. struct NewMenu PrefsNewMenu[] = {
  151.    NM_TITLE, "Project", NULL, 0, NULL, NULL,
  152.    NM_ITEM,  "Open...", "O", 0, 0L, (APTR)PrefsPREFS_OPEN,
  153.    NM_ITEM,  "Save As...", "A", 0, 0L, (APTR)PrefsPREFS_SAVEAS,
  154.    NM_ITEM,  "About", "B", 0, 0L, (APTR)PrefsPREFS_ABOUT,
  155.    NM_ITEM,  "Quit", "Q", 0, 0L, (APTR)PrefsPREFS_QUIT,
  156.    NM_TITLE, "Edit", NULL, 0, NULL, NULL,
  157.    NM_ITEM,  "Last Saved", "L", 0, 0L, (APTR)PrefsPREFS_LAST,
  158.    NM_ITEM,  "Restore", "R", 0, 0L, (APTR)PrefsPREFS_RESTORE,
  159.    NM_END, NULL, NULL, 0, 0L, NULL
  160. };
  161.  
  162. UWORD PrefsGTypes[] = {
  163.    BUTTON_KIND,
  164.    STRING_KIND,
  165.    STRING_KIND,
  166.    CHECKBOX_KIND,
  167.    BUTTON_KIND,
  168.    BUTTON_KIND,
  169.    BUTTON_KIND,
  170.    BUTTON_KIND,
  171.    BUTTON_KIND,
  172.    LISTVIEW_KIND
  173. };
  174.  
  175. /* heights and widths for gadgets are recomputed according to the font */
  176. /* numbers shown here reflect topaz 8 */
  177. struct NewGadget PrefsNGad[] = {
  178.    22,    197, 53,  24, "_Save", NULL, PREFS_SAVE, PLACETEXT_IN, NULL, (APTR)PREFS_SAVEClicked,
  179.    34,    77,  176, 22, "Su_ffix", NULL, -1, PLACETEXT_ABOVE, NULL, (APTR)PREFS_SUFFIXClicked,
  180.    34,    118, 176, 22, "Co_mmand", NULL, -1, PLACETEXT_ABOVE, NULL, (APTR)PREFS_COMMANDClicked,
  181.    35,    160, 26,  11, "Asynchronous", NULL, -1, PLACETEXT_RIGHT, NULL, (APTR)PREFS_ASYNCHClicked,
  182.    358, 197, 53,  24, "_Cancel", NULL, PREFS_CANCEL, PLACETEXT_IN, NULL, (APTR)PREFS_CANCELClicked,
  183.    237, 147, 53,  24, "_New", NULL, PREFS_NEW, PLACETEXT_IN, NULL, (APTR)PREFS_NEWClicked,
  184.    298, 147, 53,  24, "C_opy", NULL, PREFS_COPY, PLACETEXT_IN, NULL, (APTR)PREFS_COPYClicked,
  185.    358, 147, 53,  24, "_Del", NULL, PREFS_DELETE, PLACETEXT_IN, NULL, (APTR)PREFS_DELETEClicked,
  186.    187, 197, 53,  24, "_Use", NULL, PREFS_USE, PLACETEXT_IN, NULL, (APTR)PREFS_USEClicked,
  187.    237, 19,  140, 121,"Suffixes", NULL, PREFS_SUFFIXES, PLACETEXT_ABOVE, NULL, (APTR)PREFS_SUFFIXESClicked
  188. };
  189.  
  190. ULONG PrefsGTags[] = {
  191.     (GT_Underscore), '_', (TAG_DONE),
  192.  
  193.     (GTST_MaxChars), MAX_LENGTH, (STRINGA_Justification), (GACT_STRINGLEFT),
  194.     (GT_Underscore), '_', (TAG_DONE),
  195.  
  196.     (GTST_MaxChars), MAX_LENGTH, (STRINGA_Justification), (GACT_STRINGLEFT),
  197.     (GT_Underscore), '_', (TAG_DONE),
  198.  
  199.     (TAG_DONE),
  200.     (GT_Underscore), '_', (TAG_DONE),
  201.     (GT_Underscore), '_', (TAG_DONE),
  202.     (GT_Underscore), '_', (TAG_DONE),
  203.     (GT_Underscore), '_', (TAG_DONE),
  204.     (GT_Underscore), '_', (TAG_DONE),
  205.     (TAG_DONE)
  206. };
  207.  
  208. #ifdef __GNUC__
  209. inline
  210. #endif
  211. UWORD ComputeX( UWORD value ) {
  212.    return(( UWORD )((( FontX * value ) + (FontX >> 1) ) / FontX ));
  213. }
  214.  
  215. #ifdef __GNUC__
  216. inline
  217. #endif
  218. UWORD ComputeY( UWORD value ) {
  219.    return(( UWORD )((( FontY * value ) + (FontY >> 1 ) ) / FontY ));
  220.  
  221. }
  222.  
  223. /* find the length the gadget Buttons should be
  224.  * bases its length on the length of "Cancel"
  225.  * if "Cancel is not the longest gadget word, change Longest
  226.  * Also recalculate the layout based on the font chosen
  227.  */
  228. void ComputeGadgets(UWORD Width, UWORD Height) {
  229.  
  230.     static struct IntuiText IText[] = {
  231.     1, 0, JAM2, 115, 22, &Font, "Cancel ", NULL,
  232.     1, 0, JAM2, 115, 22, &Font, "Copy ", NULL
  233.     };
  234.  
  235.     int len = IntuiTextLength(&IText[0]);
  236.     int savelen = IntuiTextLength(&IText[1]);
  237.     int height = 1.5*FontY;
  238.  
  239.     /* fill in zoom now */
  240.     Zoom[2] = (Width >> 1);
  241.     Zoom[3] = Scr->BarHeight;
  242.  
  243.     PrefsNGad[PREFS_NEW].ng_Width =
  244.     PrefsNGad[PREFS_DELETE].ng_Width =
  245.     PrefsNGad[PREFS_COPY].ng_Width = savelen;
  246.  
  247.     PrefsNGad[PREFS_USE].ng_Width =
  248.     PrefsNGad[PREFS_SAVE].ng_Width =
  249.     PrefsNGad[PREFS_CANCEL].ng_Width = len;
  250.  
  251.     PrefsNGad[PREFS_COMMAND].ng_Height =
  252.     PrefsNGad[PREFS_SUFFIX].ng_Height =
  253.     PrefsNGad[PREFS_NEW].ng_Height =
  254.     PrefsNGad[PREFS_DELETE].ng_Height =
  255.     PrefsNGad[PREFS_USE].ng_Height =
  256.     PrefsNGad[PREFS_COPY].ng_Height =
  257.     PrefsNGad[PREFS_SAVE].ng_Height =
  258.     PrefsNGad[PREFS_CANCEL].ng_Height = height;
  259.  
  260.     /* Recompute Suffix listview width and height and top */
  261.     PrefsNGad[PREFS_SUFFIXES].ng_Width = 140 *((float)FontX / 8);
  262.     PrefsNGad[PREFS_SUFFIXES].ng_Height= 10*FontY;
  263.     PrefsNGad[PREFS_SUFFIXES].ng_TopEdge = OffY + FontY;
  264.  
  265.     PrefsNGad[PREFS_SUFFIXES].ng_LeftEdge =
  266.     PrefsNGad[PREFS_NEW].ng_LeftEdge =    PrefsLeft + Width - (FontX << 1)-
  267.     PrefsNGad[PREFS_SUFFIXES].ng_Width;
  268.  
  269.     /* Put the COPY, NEW, SAVE Gadgets right under the listview */
  270.     PrefsNGad[PREFS_NEW].ng_TopEdge =
  271.     PrefsNGad[PREFS_DELETE].ng_TopEdge =
  272.     PrefsNGad[PREFS_COPY].ng_TopEdge = PrefsNGad[PREFS_SUFFIXES].ng_TopEdge +
  273.     PrefsNGad[PREFS_SUFFIXES].ng_Height;
  274.  
  275.     PrefsNGad[PREFS_DELETE].ng_LeftEdge = PrefsLeft + Width -
  276.     (FontX << 1) - savelen;
  277.  
  278.     PrefsNGad[PREFS_COPY].ng_LeftEdge = (PrefsNGad[PREFS_NEW].ng_LeftEdge +
  279.     PrefsNGad[PREFS_DELETE].ng_LeftEdge) >> 1;
  280.  
  281.     /* Put the SAVE USE CANCEL Gadgets at the Bottom */
  282.     PrefsNGad[PREFS_USE].ng_TopEdge =
  283.     PrefsNGad[PREFS_SAVE].ng_TopEdge =
  284.     PrefsNGad[PREFS_CANCEL].ng_TopEdge = Height - height - (FontY >> 1);
  285.  
  286.     PrefsNGad[PREFS_SAVE].ng_LeftEdge = PrefsLeft + FontX;
  287.     PrefsNGad[PREFS_CANCEL].ng_LeftEdge = PrefsLeft + Width - len - FontX;
  288.     PrefsNGad[PREFS_USE].ng_LeftEdge = (PrefsNGad[PREFS_SAVE].ng_LeftEdge +
  289.     PrefsNGad[PREFS_CANCEL].ng_LeftEdge) >> 1;
  290.  
  291.     /* put Suffix, Command and Asynch Boxes under the title */
  292.     PrefsNGad[PREFS_SUFFIX].ng_TopEdge = OffY + ComputeY(11) + 3.5*FontY;
  293.     PrefsNGad[PREFS_COMMAND].ng_TopEdge = PrefsNGad[PREFS_SUFFIX].ng_TopEdge +
  294.     height + (FontY << 1);
  295.     PrefsNGad[PREFS_ASYNCH].ng_TopEdge = PrefsNGad[PREFS_COMMAND].ng_TopEdge +
  296.     height + (FontY << 1);
  297.  
  298. }
  299.  
  300. void ComputeFont( UWORD *width, UWORD *height ) {
  301.  
  302.     Font.ta_Name = GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  303.     Font.ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  304.     FontX = GfxBase->DefaultFont->tf_XSize;
  305.  
  306.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  307.     OffX = Scr->WBorLeft;
  308.  
  309.     *width =  50 * FontX;
  310.     *height = 18 * FontY;
  311.  
  312.     /* if the window is too big with the current font, use topaz 8 */
  313.     if ( *width && *height ) {
  314.     if (( ComputeX( *width ) + OffX + Scr->WBorRight ) > Scr->Width )
  315.         goto UseTopaz;
  316.     if (( ComputeY( *height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  317.         goto UseTopaz;
  318.     }
  319.     return;
  320.  
  321. UseTopaz:
  322.     Font.ta_Name = "topaz.font";
  323.     FontX = FontY = Font.ta_YSize = 8;
  324.     *width = 400;
  325.     *height = 144;
  326.  
  327. }
  328.  
  329.  
  330. void PrintTitle( void )
  331. {
  332.     static char *PrefsIText[] = {
  333.     "Show V1.0",
  334.     "©1994 Jeff Shepherd",
  335.     };
  336.  
  337.     struct IntuiText it = {
  338.     1, 0, JAM2, 120, 4, &Font, NULL, NULL
  339.     };
  340.  
  341.     UWORD cnt;
  342.     UWORD titlelen = (strlen(PrefsIText[1]) + 2) *FontX;
  343.  
  344.     ComputeFont( &PrefsWidth, &PrefsHeight );
  345.  
  346.     DrawBevelBox( PrefsWnd->RPort,
  347.     OffX + ComputeX(34),
  348.     OffY + ComputeY(11),
  349.     titlelen,
  350.     2.5*FontY,
  351.     GT_VisualInfo, VisualInfo,
  352.     GTBB_Recessed, TRUE,
  353.     TAG_DONE);
  354.  
  355.     for ( cnt = 0; cnt < Prefs_TNUM; cnt++ ) {
  356.     it.IText = PrefsIText[cnt];
  357.     it.LeftEdge  =    OffX + ComputeX(34+(titlelen >> 1) - (IntuiTextLength(&it) >> 1));
  358.     it.TopEdge = OffY + ComputeY( 11 + (FontY >> 2) + cnt*FontY);
  359.     PrintIText( PrefsWnd->RPort, &it, 0, 0 );
  360.    }
  361. }
  362.  
  363. #ifdef TEST
  364. struct List *MakeList(struct SuffixNode *SNode, int len) {
  365.     struct List *retval = AllocMem(sizeof(struct List),MEMF_PUBLIC|MEMF_CLEAR);
  366.     int i;
  367.  
  368.     if (retval) {
  369.     NewList(retval);
  370.  
  371.     for (i=0; i < len; i++,SNode++) {
  372.  
  373.         struct SuffixList *NewNode = MakeNode(SNode->suffix,
  374.         SNode->command, SNode->Asynch);
  375.         if (NewNode)
  376.         AddHead(retval,(struct Node *)NewNode);
  377.         else break;
  378.     } /* for */
  379.     } /* if */
  380.     return retval;
  381. }
  382. #endif
  383.  
  384. void HandlePrefsIDCMP(void)
  385. {
  386.     struct IntuiMessage *m;
  387.     struct IntuiMessage PrefsMsg;
  388.     struct MenuItem *n;
  389.     LONG sig=0, sig2 =0;
  390.     ULONG signals;
  391.     LONG notifysig;
  392.     LONG winsig = 1 << PrefsWnd->UserPort->mp_SigBit;
  393.  
  394.     int      (*func)(struct IntuiMessage *,struct Gadget **);
  395.     int      (*menufunc)(struct Gadget **);
  396.     BOOL    running = TRUE;
  397.  
  398. /* automatically adjusts font when prefs are changed */
  399. #ifdef __GNUC__
  400.     struct NotifyRequest nr __attribute__((aligned(16)));
  401.     struct NotifyRequest nr2 __attribute__((aligned(16)));
  402. #else
  403.     _aligned struct NotifyRequest nr;
  404.     _aligned struct NotifyRequest nr2;
  405. #endif
  406.  
  407.      if ( ((sig = AllocSignal(-1L)) != -1) && ((sig2 = AllocSignal(-1L)) != -1) )  {
  408.     notifysig = (1L << sig) | (1L << sig2);
  409.     nr.nr_stuff.nr_Signal.nr_SignalNum = sig;
  410.     nr2.nr_stuff.nr_Signal.nr_SignalNum = sig2;
  411.  
  412.     nr.nr_Name = "env:sys/font.prefs";
  413.     nr2.nr_Name = "env:sys/screenmode.prefs";
  414.  
  415.     nr.nr_Flags = nr2.nr_Flags = NRF_SEND_SIGNAL;
  416.     nr.nr_stuff.nr_Signal.nr_Task =
  417.     nr2.nr_stuff.nr_Signal.nr_Task = (struct Task *)FindTask(NULL);
  418.  
  419.     if ( ((StartNotify(&nr)) == DOSTRUE) && ((StartNotify(&nr2)) == DOSTRUE) ) {
  420.  
  421.         while (running) {
  422.  
  423.         signals =Wait(notifysig | winsig);
  424.  
  425.         if (signals & winsig) {
  426.             while(m = GT_GetIMsg(PrefsWnd->UserPort)) {
  427.  
  428.             CopyMem(m , &PrefsMsg, sizeof(struct IntuiMessage));
  429.             GT_ReplyIMsg(m);
  430.  
  431.             switch (PrefsMsg.Class) {
  432.  
  433.                 case IDCMP_REFRESHWINDOW:
  434.                 GT_BeginRefresh(PrefsWnd);
  435.                 PrintTitle();
  436.                 GT_EndRefresh(PrefsWnd, TRUE);
  437.                 break;
  438.  
  439.                 case IDCMP_CLOSEWINDOW:
  440.                 running = FALSE;
  441.                 break;
  442.  
  443.                 case IDCMP_GADGETUP:
  444.                 case IDCMP_GADGETDOWN:
  445.                 func = (void *) ((struct Gadget *)PrefsMsg.IAddress)->UserData;
  446.                 running = func(&PrefsMsg,PrefsGadgets);
  447.                 break;
  448.  
  449.                 case IDCMP_MENUPICK:
  450.                 while(PrefsMsg.Code != MENUNULL && running) {
  451.                 n = ItemAddress(PrefsMenus, PrefsMsg.Code);
  452.                 menufunc = (void *)(GTMENUITEM_USERDATA(n));
  453.                 running = menufunc(PrefsGadgets);
  454.                 PrefsMsg.Code = n->NextSelect;
  455.                 }
  456.                 break;
  457.  
  458.                 case IDCMP_VANILLAKEY:
  459.                 switch (PrefsMsg.Code) {
  460.  
  461.                     case 'S':
  462.                     case 's':
  463.                     running = PREFS_SAVEClicked(&PrefsMsg,PrefsGadgets);
  464.                     break;
  465.  
  466.                     case 'U':
  467.                     case 'u':
  468.                     running = PREFS_USEClicked(&PrefsMsg,PrefsGadgets);
  469.                     break;
  470.  
  471.                     case 'C':
  472.                     case 'c':
  473.                     /* saves calling CANCELClicked */
  474.                     running = FALSE;
  475.                     break;
  476.  
  477.                     case 'N':
  478.                     case 'n':
  479.                     running = PREFS_NEWClicked(&PrefsMsg,PrefsGadgets);
  480.                     break;
  481.  
  482.                     case 'D':
  483.                     case 'd':
  484.                     running = PREFS_DELETEClicked(&PrefsMsg,PrefsGadgets);
  485.                     break;
  486.  
  487.                     case 'F':
  488.                     case 'f':
  489.                     ActivateGadget(PrefsGadgets[PREFS_SUFFIX], PrefsWnd,NULL);
  490.                     break;
  491.  
  492.                     case 'M':
  493.                     case 'm':
  494.                     ActivateGadget(PrefsGadgets[PREFS_COMMAND], PrefsWnd,NULL);
  495.                     break;
  496.                 } /* switch (PrefsMsg.Code) */
  497.             } /* switch (PrefsMsg.Class) */
  498.             } /* while (GetMsg) */
  499.         } /* if (WinSig) */
  500.         else {
  501.          /* (signals & notifysig) == TRUE */
  502.             GT_SetGadgetAttrs(PrefsGadgets[PREFS_SUFFIXES],PrefsWnd,NULL,
  503.             (GTLV_Labels), ~0,
  504.             (TAG_DONE) );
  505.  
  506.             DestroyWindow();
  507.             Delay(150);
  508.             CreateWindow();
  509.             PrintTitle();
  510.             GT_SetGadgetAttrs(PrefsGadgets[PREFS_SUFFIXES],PrefsWnd,NULL,
  511.             (GTLV_Labels), Suffix_List,
  512.             (TAG_DONE) );
  513.  
  514.             winsig = 1L << PrefsWnd->UserPort->mp_SigBit;
  515.         } /* if */
  516.         } /* while (running) */
  517.         EndNotify(&nr2);
  518.         EndNotify(&nr);
  519.     } /* StartNotify */
  520.     else {
  521.         Error("Not enough memory for NotifyRequest.");
  522.     }
  523.     FreeSignal(sig);
  524.     FreeSignal(sig2);
  525.     } /* AllocSignal */
  526.     else {
  527.     Error("Could not allocate signal.");
  528.     }
  529. }
  530.  
  531. int main(int argc, char **argv) {
  532.  
  533.     FromWB = (argc == 0) ? TRUE : FALSE;
  534.  
  535.     if ( !(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
  536.     panic("Cannot open intuition library version 37",1);
  537.  
  538.      if ( !(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
  539.     panic("Cannot open graphics library version 37",8);
  540.  
  541.     if ( !(GadToolsBase = OpenLibrary("gadtools.library",37)))
  542.     panic("Cannot open gadtools library version 37",2);
  543.  
  544.     if ( !(AslBase = OpenLibrary("asl.library",37)))
  545.     panic("Cannot open ASL library version 37",10);
  546.  
  547.     if ( !(IFFParseBase = OpenLibrary("iffparse.library",37)))
  548.     panic("Cannot open iffparse library version 37",11);
  549.  
  550.  
  551.     CreateWindow();
  552.  
  553. #ifndef TEST
  554.     if ( !(Suffix_List = AllocMem(sizeof(struct List),MEMF_PUBLIC|MEMF_CLEAR)))
  555.     panic("Cannot allocate list",9);
  556.     if ( !(Duplicate = AllocMem(sizeof(struct List),MEMF_PUBLIC|MEMF_CLEAR)))
  557.     panic("Cannot allocate list",9);
  558.  
  559.     NewList(Suffix_List);
  560.     NewList(Duplicate);
  561.     LoadPrefs("env:show.prefs",PrefsGadgets,TRUE,Duplicate);
  562. #else
  563.     if (! (Suffix_List=MakeList(test,4)))
  564.     panic("Could not initialize listview list",9);
  565.  
  566.     GT_SetGadgetAttrs(PrefsGadgets[PREFS_SUFFIXES],PrefsWnd,NULL,
  567.     (GTLV_Labels), Suffix_List,
  568.     (TAG_DONE) );
  569. #endif
  570.  
  571.     PrintTitle();
  572.     HandlePrefsIDCMP();
  573.     panic(NULL,0);
  574. }
  575.  
  576. /* clean up time */
  577. void panic(char *error, int retval) {
  578.  
  579.     /* print the error message if any */
  580.     if (error) {
  581.     if (FromWB)
  582.         Error(error);
  583.     else
  584.         fprintf(stderr,"ERROR: %s\n",error);
  585.     }
  586.  
  587.  
  588.     /* destroy List */
  589.     if (Duplicate) {
  590.     Destroy_List(Duplicate);
  591.     FreeMem(Duplicate, sizeof(struct List));
  592.     }
  593.  
  594.     if (Suffix_List) {
  595.     Destroy_List(Suffix_List);
  596.     FreeMem(Suffix_List, sizeof(struct List));
  597.     }
  598.  
  599.     DestroyWindow();
  600.  
  601.  
  602.     if (IFFParseBase)
  603.     CloseLibrary(IFFParseBase);
  604.  
  605.     if (AslBase)
  606.     CloseLibrary(AslBase);
  607.  
  608.     if (GadToolsBase)
  609.     CloseLibrary(GadToolsBase);
  610.  
  611.     if (GfxBase)
  612.     CloseLibrary((struct Library *)GfxBase);
  613.  
  614.     if (IntuitionBase)
  615.     CloseLibrary((struct Library *)IntuitionBase);
  616.  
  617.     exit(retval);
  618. }
  619.  
  620.  
  621. /* stubs */
  622. #if 0
  623. void DrawBevelBox( struct RastPort *rport, long left, long top, long width,
  624.     long height, Tag tag1, ... ) {
  625.        DrawBevelBoxA(rport,left,top,width,height,(struct TagItem *)&tag1);
  626. }
  627. #endif
  628.  
  629.  
  630. void CreateWindow(void) {
  631.  
  632.     UWORD wleft = PrefsLeft, wtop = PrefsTop;
  633.     UWORD ww, wh;
  634.     struct NewGadget  ng;
  635.     struct Gadget  *g;
  636.     UWORD    lc, tc;
  637.  
  638.     if ( !(Scr= LockPubScreen(NULL)) )
  639.     panic("Could not lock public screen",3);
  640.  
  641.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  642.     panic("Cannot get visualinfo",4);
  643.  
  644.     ComputeFont( &PrefsWidth, &PrefsHeight );
  645.     ComputeGadgets(PrefsWidth, PrefsHeight);
  646.  
  647.     ww = ComputeX( PrefsWidth );
  648.     wh = ComputeY( PrefsHeight );
  649.  
  650.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  651.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  652.  
  653.     if ( ! ( g = CreateContext( &PrefsGList )))
  654.     panic("Cannot create context",5);
  655.  
  656.     /* make gadgets */
  657.     for( lc = 0, tc = 0; lc < Prefs_CNT; lc++ ) {
  658.     CopyMem(&PrefsNGad[lc],&ng,sizeof(struct NewGadget));
  659.  
  660.     ng.ng_VisualInfo = VisualInfo;
  661.     ng.ng_TextAttr    = &Font;
  662.     ng.ng_LeftEdge    = OffX + ComputeX( ng.ng_LeftEdge );
  663.     ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  664.     ng.ng_Width    = ComputeX( ng.ng_Width );
  665.     ng.ng_Height    = ComputeY( ng.ng_Height);
  666.  
  667.     PrefsGadgets[lc] = g = CreateGadgetA(PrefsGTypes[lc], g, &ng, (struct TagItem *)&PrefsGTags[tc]);
  668.  
  669.     while(PrefsGTags[tc]) tc += 2;
  670.         tc++;
  671.  
  672.     if (!g)
  673.         panic("Cannot create gadgets",6);
  674.     }
  675.  
  676.     if (!(PrefsMenus = CreateMenus(PrefsNewMenu,
  677.     GTMN_NewLookMenus, TRUE,
  678.     GTMN_FrontPen, 1,
  679.     TAG_DONE)))
  680.     panic("Cannot create menus",7);
  681.  
  682.     LayoutMenus(PrefsMenus, VisualInfo, TAG_DONE);
  683.  
  684.     if (!( PrefsWnd = OpenWindowTags( NULL,
  685.     WA_Left, wleft,
  686.     WA_Top,  wtop,
  687.     WA_Width,  ww + OffX + Scr->WBorRight,
  688.     WA_Height, wh + OffY + Scr->WBorBottom,
  689.     WA_IDCMP,  BUTTONIDCMP|LISTVIEWIDCMP|STRINGIDCMP|CHECKBOXIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY,
  690.     WA_Flags,  WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  691.     WA_Gadgets, PrefsGList,
  692.     WA_Title,  PrefsWdt,
  693.     WA_NewLookMenus, TRUE,
  694.     WA_Zoom, Zoom,
  695.     WA_PubScreen,  Scr,
  696.     TAG_DONE )))
  697.     panic("Cannot open window",7);
  698.  
  699.     SetMenuStrip( PrefsWnd, PrefsMenus );
  700.     GT_RefreshWindow( PrefsWnd, NULL );
  701. }
  702.  
  703. void DestroyWindow(void) {
  704.     if (PrefsMenus) {
  705.     ClearMenuStrip(PrefsWnd);
  706.     FreeMenus(PrefsMenus);
  707.     }
  708.  
  709.     if (PrefsWnd) {
  710.     /* Reply to any Messages */
  711.     struct Message *mess;
  712.     while(mess = GetMsg(PrefsWnd->UserPort))
  713.         ReplyMsg(mess);
  714.     CloseWindow(PrefsWnd);
  715.     }
  716.  
  717.     if (PrefsGList)
  718.     FreeGadgets(PrefsGList);
  719.  
  720.     if (VisualInfo)
  721.     FreeVisualInfo(VisualInfo);
  722.  
  723.     if (Scr)
  724.     UnlockPubScreen(NULL,Scr);
  725. }
  726.  
  727. @
  728.